<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="java.util.*,com.telecom.cms.dto.*,com.telecom.cms.dao.*"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
	prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
	prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
	prefix="logic"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
	<head>
		<title>JSP for SysTeamForm form</title>
		<LINK href="css/default.css" rel=stylesheet>
		<LINK href="css/button.css" rel=stylesheet>
		<script type="text/javascript">
			function opchange(o){
		var obj=document.all.ObjSelect;
		for(i=0;i<obj.length;i++){
			obj.options[i].selected=true;
		}
		document.idaTemplateForm.method.value=o;
		document.idaTemplateForm.submit();
	}
	
	function selTemplate(tmptid){
		document.location.href = 'idaTemplate.do?method=rsTemp4pickup&templateId=' + tmptid;
	}

	function Atomoption (text,value){
		this.text=text;
		this.value=value;
	}
	
	var atoms=new Array();
	
	function ChangeGroup()
	{ 
		var i,iGroupIndex;
		iGroupIndex=document.all.groups.selectedIndex;
		iAtomCount=0; 
		while (atoms[iGroupIndex][iAtomCount]!=null) 
		 iAtomCount++;
		 //计算选定组下的原子个数 
		document.all.SrcSelect.length=0;//清空选项数 
		var obj=document.all.ObjSelect;
		var objCount=obj.length;
		for(i=0;i<=iAtomCount-1;i++){//改变下拉菜单的内容 
			var flag=0;
			for(j=0;j<=objCount-1;j++){
				var ov = obj.options[j].value.split("#");
				if(ov[0]==atoms[iGroupIndex][i].value){
					flag++;
				}
			}
			if(flag==0)
			document.all.SrcSelect.add(new Option(atoms[iGroupIndex][i].text,atoms[iGroupIndex][i].value));
		}
		document.all.SrcSelect.focus();
	}
	
	function moveUp()  
	{ 
	var theObj=document.all.ObjSelect;
	for(var i=1;i<theObj.length;i++)
	 {
	  if( theObj.options[i].selected && !theObj.options[i-1].selected )
	  {
	   theObj.options[i].swapNode(theObj.options[i-1]);//与上面一个交换
	  }
	 }
	}
	  
	function moveDown()
	{ 
	var theObj=document.all.ObjSelect;
	for(var i=theObj.length-2;i>-1;i--)
	 {
	  if( theObj.options[i].selected && !theObj.options[i+1].selected )
	  {
	   theObj.options[i].swapNode(theObj.options[i+1]);
	  }
	 }
	}
	
	function moveLeftOrRight(fromObj,toObj)
	{
	 var lengthOfToObj=toObj.length;
	 for(var i=fromObj.length-1;i>-1;i--)
	 {
	  if(fromObj.options[i].selected)
	  {
	   toObj.add(new Option(fromObj.options[i].text,fromObj.options[i].value),lengthOfToObj);//new option(text,value,true,true)
	   toObj.options[lengthOfToObj].selected=true;
	   fromObj.options[i].removeNode(true);
	  }
	 }
	}
	
	function submitchange(){
		obj=document.defPickupForm.ObjSelect;
		for(i=0;i<obj.length;i++){
			obj.options[i].selected=true;
		}
		document.defPickupForm.target="rsFrame";
	}
	
	function changeOrderRule(sel){
		var i=sel.selectedIndex;
		var value=sel.options[i].value;
		var text=sel.options[i].innerHTML;
		vstate=value.split("#");
		tstate=text.split("[");
		if(vstate[1]==null){
		sel.options[i].value=vstate[0]+"#asc";
		sel.options[i].innerHTML=tstate[0]+"[正序]";
		}
		if(vstate[1]=="asc"){
		sel.options[i].value=vstate[0]+"#desc";
		sel.options[i].innerHTML=tstate[0]+"[逆序]";
		}
		if(vstate[1]=="desc"){
		sel.options[i].value=vstate[0];
		sel.options[i].innerHTML=tstate[0];
		}
	}
	function changeInput(o){
		if(o=='text'){
			document.getElementById("uploaddept").style.display="none";
			document.getElementById("textdept").style.display="";
		}
		if(o=='file'){
			document.getElementById("uploaddept").style.display="";
			document.getElementById("textdept").style.display="none";
		}
	}
	</script>
	</head>
	<body>
		<html:form action="/defPickup" enctype="multipart/form-data"
			onsubmit="submitchange()">
			<table width="770" cellspacing="0" cellpadding="0" border="0"
				align="center">
				<tbody>
					<tr>
						<td width="3" height="31">
							<img height="31" src="./images/table_01.gif" width="3" />
						</td>
						<td background="./images/table_02.gif" height="31">
							<table cellspacing="0" cellpadding="0" width="146" align="left"
								border="0">
								<tbody>
									<tr>
										<td width="51" background="./images/title_1_bg.gif">
											<img height="31" src="./images/title_1.gif" width="51" />
										</td>
										<td width="95" background="./images/title_1_bg.gif">
											<span class="color_b_666">自定义取数</span>
										</td>
									</tr>
								</tbody>
							</table>
						</td>
						<td width="3">
							<img height="31" src="./images/table_03.gif" width="3" />
						</td>
					</tr>
					<tr>
						<td background="images/table_04.gif">
							<img height="5" src="images/table_04.gif" width="3">
						</td>
						<td style="PADDING-TOP: 3px" valign="top">
							<table align="center" width="770" cellpadding="0" border="0"
								cellspacing="1">
								<tr>
									<td>
										自定义取数方式:
										<html:radio property="method" value="numcheck"
											onclick="changeInput('text')" />
										号码反查
										<html:radio property="method" value="defsql"
											onclick="changeInput('text')" />
										自定义SQL
										<html:radio property="method" value="upload"
											onclick="changeInput('file')" />
										上传文件

									</td>
									<td>
										账务年:
										<html:select property="billing_cycle_y">
											<%
												Calendar myCalendar = Calendar.getInstance();
														for (int myYear = 2006; myYear < 2010; myYear++) {
											%>
											<option value="<%=myYear%>"
												<%=(myCalendar.get(1) == myYear ? "selected"
										: "")%>>
												<%=myYear%>
											</option>
											<%
												}
											%>
										</html:select>
									</td>
								</tr>
								<tr>
									<td>
										请选择号码类型:
										<html:radio property="numtype" value="Accs_Nbr" />
										接入号码
										<html:radio property="numtype" value="Acct_Id" />
										账户标识
										<html:radio property="numtype" value="Cust_Id" />
										客户标识
									</td>
									<td>
										账务月:
										<html:select property="billing_cycle_m">
											<%
												Calendar myCalendar = Calendar.getInstance();
														for (int myMon = 1; myMon < 13; myMon++) {
											%>
											<option value="<%=myMon%>"
												<%=(myCalendar.get(2) == myMon ? "selected"
												: "")%>>
												<%=myMon%>
												月
											</option>
											<%
												}
											%>
										</html:select>
									</td>
								</tr>
								<tr id="uploaddept" style="display: none;">
									<td>
										上传文件:
										<html:file property="theFile"></html:file>
									</td>
									<td>
										<html:radio property="filetype" value="excel" />
										EXCEL格式
										<html:radio property="filetype" value="txt" />
										TXT格式
									</td>
								</tr>
							</table>
							<table id="textdept" border="0" cellpadding="0" cellspacing="0"
								align="center">
								<tr>
									<td>
										<textarea name="textarea" cols="93" rows="20"></textarea>
									</td>
								</tr>
							</table>
							<table border="0" cellpadding="0" cellspacing="0" align="center">
								<tr>
									<td width="100" align="center">
										选择模板：
									</td>
									<td align="left">
										<html:select property="idaTemplate.templateId"
											onchange="selTemplate(this.value);"
											value="${idaTemplate.templateId}">
											<html:option value="">无选择</html:option>
											<logic:present name="templateList" scope="request">
												<logic:iterate name="templateList" id="t">
													<logic:equal name="t" property="templateTypeId" value="20">
														<html:option value="${t.templateId}">
															<bean:write name="t" property="templateName" />
														</html:option>
													</logic:equal>
												</logic:iterate>
											</logic:present>
										</html:select>
									</td>
								</tr>
							</table>

							<table width='100%' border='0' cellspacing='' cellpadding='2'>
								<tr>
									<td align="left" colspan="2">
										<table width='100%' border='0' cellspacing='1' cellpadding='2'>
											${paramStr}
										</table>
									</td>
								</tr>
								<tr>
									<td align="left" colspan="2">
										<table width='100%' border='0' cellspacing='0' cellpadding='2'>
											<tr align="center" height="25">
												<td background="images/atom_02.gif" width="20%">
													结果字段类型：
												</td>
												<td background="images/atom_02.gif" width="25%">
													可选择结果字段：
												</td>
												<td background="images/atom_02.gif" width="10%">
													&nbsp;
												</td>
												<td background="images/atom_02.gif" width="25%">
													已选择结果字段：
												</td>
												<td background="images/atom_02.gif" width="20%">
													&nbsp;
												</td>
											</tr>
											<tr align="center" valign="top">
												<td>
													<select name="groups" id="groups" onchange="ChangeGroup()">
														<%
															IdaDAO idadao = new IdaDAO();
																List grouplist = idadao.findAllAtomGroup();
																int idx = 0;
																for (int i = 0; i < grouplist.size(); i++) {
																	SEG_BIZ_GROUP_DEFDTO groupdto = (SEG_BIZ_GROUP_DEFDTO) grouplist
																			.get(i);
														%>
														<option value=<%=groupdto.getATOM_GROUP_ID()%>><%=groupdto.getATOM_GROUP_NAME()%></option>
														<script type="text/javascript">atoms[<%=idx%>]=new Array(); </script>
														<%
															List groupAtoms = idadao.findGroupAtoms(groupdto
																			.getATOM_GROUP_ID());
																	if (groupAtoms != null && groupAtoms.size() > 0)
																		for (int j = 0; j < groupAtoms.size(); j++) {
																			SEG_BIZ_ATOM_DEFDTO showdto = (SEG_BIZ_ATOM_DEFDTO) groupAtoms
																					.get(j);
														%>
														<script type="text/javascript">atoms[<%=idx%>][<%=j%>]=new Atomoption('<%=showdto.getBIZ_ATOM_NAME()%>',<%=showdto.getBIZ_ATOM_ID()%>) </script>
														<%
															}
																	idx++;
																}
														%>
													</select>
												</td>
												<td>
													<select name="SrcSelect" size=15
														style="font-size: 10pt; width: 200px;" multiple>
													</select>
												</td>
												<td align="center" valign="middle">
													<a
														href="javascript:moveLeftOrRight(document.all.SrcSelect,document.all.ObjSelect)"><img
															src="images/button_add_arrow.gif" border="0"> </a>
													<br>
													<br>
													<a
														href="javascript:moveLeftOrRight(document.all.ObjSelect,document.all.SrcSelect)"><img
															src="images/button_del_arrow.gif" border="0"> </a>
												</td>
												<td>
													<select name="ObjSelect" ondblclick="changeOrderRule(this)"
														size=15 style="font-size: 10pt; width: 200px;" multiple>
														<%
															IdaTemplate rsTemplate = (IdaTemplate) request
																		.getAttribute("idaTemplate");
																if (rsTemplate != null) {
																	List rsAtomList = rsTemplate.getAtomList();
																	for (int i = 0; i < rsAtomList.size(); i++) {
																		IdaTemplateAtomResult atom = (IdaTemplateAtomResult) rsAtomList
																				.get(i);
																		String vo = "";
																		String to = atom.getResultOrderRule();
																		if (to.equals("asc")) {
																			to = "正序";
																		} else if (to.equals("desc")) {
																			to = "逆序";
																		}
																		if (atom.getResultOrderRule() != null
																				&& !atom.getResultOrderRule().equals("")) {
																			vo = "#" + atom.getResultOrderRule();
																			to = "[" + to + "]";
																		}
														%>
														<option value="<%=atom.getBizAtomId() + vo%>"><%=atom.getBizAtomName() + to%></option>
														<%
															}
																}
														%>
													</select>
												</td>
												<td align="left">
													<a href="javascript:moveUp()"><img
															src="images/button_up.gif" border="0"> </a>
													<br>
													<br>
													<a href="javascript:moveDown()"><img
															src="images/button_down.gif" border="0"> </a>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>

							<html:submit value="提交"></html:submit>
							<html:cancel value="取消"></html:cancel>
						</td>
						<td background="images/table_05.gif">
							<img height="5" src="images/table_05.gif" width="3">
						</td>
					</tr>
					<tr height="3">
						<td height="3">
							<img height="12" src="images/table_06.gif" width="3">
						</td>
						<td height="3">
							<img height="3" src="images/table_07.gif" width="764">
						</td>
						<td height="3">
							<img height="12" src="images/table_08.gif" width="3">
						</td>
					</tr>
				</tbody>
			</table>
		</html:form>
	</body>
</html>